/*
 * Copyright(c) 2020-2100 万达信息股份有限公司 版权所有
 * WONDERS INFORMATION CO., LTD. ALL RIGHTS RESERVED.
 */

package com.wondersgroup.v4;

import java.util.ArrayList;
import java.util.List;

/**
 * 分类观察者和被观察者
 * @author: huym
 * @version: 1.0
 * @date: 2020/12/10
 */
public class Main {
    public static void main(String[] args) {
        Child child = new Child();
        child.wakeup();
    }
}

class Child{
    private boolean cry = false;
    private List<Observer> observers = new ArrayList<>();
    {
        observers.add(new Dad());
        observers.add(new Mun());
        observers.add(new Dog());
    }
    public boolean isCry(){
        return this.cry;
    }
    public void wakeup(){
        this.cry = true;
        observers.forEach(observer -> observer.actionOnWakeup());
    }
}

interface Observer{
    void actionOnWakeup();
}

class Dad implements Observer {
    public void feed(){
        System.out.println("dad feed......");
    }
    @Override
    public void actionOnWakeup() {
        feed();
    }
}

class Mun implements Observer {
    public void hug(){
        System.out.println("mun hug......");
    }
    @Override
    public void actionOnWakeup() {
        hug();
    }
}

class Dog implements Observer {
    public void wang(){
        System.out.println("dog wang......");
    }
    @Override
    public void actionOnWakeup() {
        wang();
    }
}